#include "PointEntity.h"
#include "View.h"

namespace FinalRendering
{
	namespace Editor
	{
		void PointEntity::Draw(View * view)
		{
			if (view->Type == View::vtPerspective)
			{
				Matrix4 mat;
				glPushAttrib(GL_ENABLE_BIT);
				glGetFloatv(GL_MODELVIEW_MATRIX, (float*)&mat);
				vec3 p;
				MatrixTransformVec3(mat, Center,p);
				glEnable(GL_TEXTURE_2D);
				glBindTexture(GL_TEXTURE_2D, GetImage()->GetTextureID());
				glPushMatrix();
				glLoadIdentity();
				glDisable(GL_LIGHTING);
				glEnable(GL_ALPHA_TEST);
				glEnable(GL_BLEND);
				
				glBegin(GL_QUADS);
				{
					glTexCoord2i(0,0);
					glVertex3f(p.x-8.0f, p.y+8.0f, p.z);
					glTexCoord2i(0,1);
					glVertex3f(p.x-8.0f, p.y-8.0f, p.z);
					glTexCoord2i(1,1);
					glVertex3f(p.x+8.0f, p.y-8.0f, p.z);
					glTexCoord2i(1,0);
					glVertex3f(p.x+8.0f, p.y+8.0f, p.z);
				}
				glEnd();
				glPopMatrix();
				glPopAttrib();
			}
			else
			{
				VMin = Center - vec3(8.0f,8.0f,8.0f);
				VMax = Center + vec3(8.0f,8.0f,8.0f);
				Entity::Draw(view);
			}
		}
	}
}